package com.example.activity;

import android.app.ListActivity;
import android.widget.SimpleAdapter;
import com.example.R;
import com.example.modle.Mp3Info;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 * User: Jasic
 * Date: 12-11-28
 */
public abstract class AResourceActivity extends ListActivity {

    /**
     * 更新资源列表
     */
    protected void updateListView() {

        SimpleAdapter adapter = buildSimpleAdapter(getMp3Infos());

        super.setListAdapter(adapter);
    }


    /**
     * 创建simpleAdapter
     * @param infos
     * @return
     */
    protected SimpleAdapter buildSimpleAdapter(List<Mp3Info> infos){

        List<Map<String, String>> maps = new ArrayList<Map<String, String>>();

        for (Mp3Info info : infos) {
            Map<String, String> map = new HashMap<String, String>();
            map.put("mp3_name", info.getMp3_Name());
            map.put("mp3_size", info.getMp3_Size());

            maps.add(map);
        }

        //创建simpleAdapter对象
        SimpleAdapter adapter = new SimpleAdapter(this, maps, R.layout.mp3info_item, new String[]{"mp3_name", "mp3_size"}, new int[]{R.id.mp3_name, R.id.mp3_size});
        return adapter;

    }

    /**
     * 实现得到mp3的所有信息
     * @return
     */
    protected abstract List<Mp3Info> getMp3Infos();
}
